#include "util/RawImage.h"

namespace util {

RawImage::RawImage(std::size_t width, std::size_t height)
  : width_(width)
  , height_(height)
{
}

Image RawImage::fromStream(std::istream& is) const
{
  Image img(width_, height_);

  for (std::size_t y = 0; y < img.getHeight() && is.good(); ++y)
  {
    for (std::size_t x = 0; x < img.getWidth() && is.good(); ++x)
    {
      img.setValue(x, y, is.get());
    }
  }
  return img;
}

void RawImage::toStream(std::ostream& os, const Image& img)
{
  for (std::size_t y = 0; y < img.getHeight() && os.good(); ++y)
  {
    for (std::size_t x = 0; x < img.getWidth() && os.good(); ++x)
    {
      os << (char)img.getValue(x, y);
    }
  }
}

} // namespace util
